<?php


use think\Route;











Route::get('admin/main/index','admin/main/index');
Route::get('admin/user/index','admin/user/index');

Route::post('admin/user/save','admin/user/save');

Route::get('jump','admin/index/jump');


//Route::get('admin/permission/index','admin/permission/index');





    // 动态注册
// Route::rule('路由表达式','路由地址','请求类型','路由参数（数组）','变量规则（数组）');
    /*
        路由规则:URL访问规则（包括静态规则和动态规则）,只有符合规则的路由才能正确访问;
        路由地址:实际访问的地址（可以是控制器操作、类的方法或者闭包）;
        请求类型:表示当前路由生效使用的请求类型,包括GET/POST/PUT/DELETE等,如果希望任何请求都能访问使用*号（默认值）。
        路由参数:路由匹配的条件约束或设置参数（用于检测或者解析）;
        路由变量:路由规则里面的动态变量以及PATH_INFO里面的参数都称之为路由变量;
        变量规则:路由规则中的变量的匹配规则（正则表达式）;

        支持任意请求规则
        Route::rule('new/:id','News/update');
        定义GET请求路由规则
        Route::get('new/:id','News/read');
        定义POST请求路由规则
        Route::post('new/:id','News/update');
        定义PUT请求路由规则
        Route::put('new/:id','News/update');
        定义DELETE请求路由规则
        Route::delete('new/:id','News/delete');
        所有请求都支持的路由规则
        Route::any('new/:id','News/read');
    */


Route::get('/','index/index/index');

Route::get('home','index/index/index');

Route::get('admin/user/index','admin/user/index');
Route::get('admin/user/update','admin/user/update');
Route::get('admin/user/delete','admin/user/delete');
Route::get('admin/user/insert','admin/user/insert');

//无参模式
//Route::get('user','index/index/user');
//必传参数
//Route::get('/url/:id','index/index/user');
//可选参数
Route::get('/user/[:id]','index/index/user');
//匹配参数
//Route::get('/user/:id$','index/index/user');

Route::get('url','index/index/url');

//闭包
Route::get('js/:id',function($id){
    if ($id>100){
        return '为您服务'.$id;
    }else{
        return '没有'.$id;
    }
});

Route::get('list','admin/user/index',['ext'=>'html|shtml']);


// 变量规则
// 越容易匹配的越往后放
//Route::get('/blog/:year/:month/:day', 'index/blog/article', [], ['year'=>'\d{4}', 'month'=>'\d{2}','day'=>'\d{2}']);
//Route::get('/blog/:id$', 'index/blog/index', [], ['id'=>'\d+']);
//Route::get('/blog/:name$', 'index/blog/read', [], ['name'=>'\w+']);

//Route::group('blog',[
//    ':year/:month/:day'=>
//        [
//            'index/blog/article',
//            'get',
//            ['year'=>'\d{4}', 'month'=>'\d{2}','day'=>'\d{2}']
//        ],
//
//   ':id$'=>
//       [
//            'index/blog/index',
//            'get',
//            ['id'=>'\d+']
//        ],
//    ':name$'=>
//        [
//            'index/blog/read',
//            'get',
//            ['name'=>'\w+']
//        ]
//
//]);


Route::group('blog', [
    ':year/:month/:day'=>
        [
            'index/blog/article',
            ['get'],
            [
                'year'=>'\d{4}',
                'month'=>'\d{2}',
                'day'=>'\d{2}'
            ]
        ],
    ':id$'=>
        [
            'index/blog/index',
            ['get'],
            ['id'=>'\d+']
        ],
    ':name$'=>
        [
            'index/blog/read',
            ['get'],
            ['name'=>'\w+']
        ],
]);





Route::get('jump','index/index/jump');

Route::get('rd','index/index/rd');

//资源路由
Route::resource('users','rest/user');


Route::get('rest/show/:id','rest/user/readpage');
Route::get('db','rest/test/index');





//静态注册
//return [
//
//    '__pattern__' => [
//        'name' => '\w+',
//    ],
//    '[hello]'     => [
//        ':id'   => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
//        ':name' => ['index/hello', ['method' => 'post']],
//    ],
//
//];
